﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using HA.ModFlow.Domain.DomainLayer;

using HA.ModFlow.Infrastructure;
using HA.Data;
using HA.ModFlow.Controls;


namespace HA.ModFlow.Controls.Windows
{
    /// <summary>
    /// winConfiningBed.xaml 的交互逻辑
    /// </summary>
    public partial class winConfiningBed : Window
    {
        public winConfiningBed(Project proj )
        {
            InitializeComponent();
            project = proj;
            ModFlowData mfData = proj.MfData;
            this.GridData = mfData.GridData;
            Gridcon = new GridConfiningBedCollection(mfData.GridData);
            _mdOption = mfData.ModelOption;
            gridconf = Gridcon.Layers;

            MenuItem itemCopy = new MenuItem();
            itemCopy.Header = "复制";
            itemCopy.Command = ApplicationCommands.Copy;

            //MenuItem itemPaste2 = new MenuItem();
            //itemPaste2.Header = "粘贴";
            //itemPaste2.InputGestureText = "Ctrl+V";
            //itemPaste2.Click += new RoutedEventHandler(itemPaste2_Click);

            ContextMenu cm = new ContextMenu();
            cm.Items.Add(itemCopy);
            //cm.Items.Add(itemPaste2);          
            this.dtgrid.ContextMenu = cm;
        }

        Project project;
        ModelOption _mdOption;
        public  List<GridConfiningBed> gridconf;     
        private GridConfiningBedCollection _gridcon;

        public GridConfiningBedCollection Gridcon
        {
            get { return _gridcon; }
            set { _gridcon = value; }
        }

        GridData _gridData;

        public GridData GridData
        {
            get { return _gridData; }
            set { _gridData = value; }
        }


        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.DataContext = this.gridconf;          
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            Gridcon.SetConfiningBed(gridconf);
            this.DialogResult = true;
            this.Close();
           
        }

        private void btnConfinging_Click(object sender, RoutedEventArgs e)
        {
            //windlgConfining winlgCon = new windlgConfining(this.GridData);
            //winlgCon.Owner = this;
            //winlgCon.ResizeMode = ResizeMode.NoResize;
            //winlgCon.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            //winlgCon.ShowInTaskbar = false;
            //winlgCon.ShowDialog();


            List<double[,]> data= this._gridData.WaterGrid.GetConfiningBed();


            CellCenterDataSet3d ds = new CellCenterDataSet3d(data,this._gridData.WaterGrid.GetIBounds(),this._gridData.RowsCount,this._gridData.ColsCount,this._gridData.LayersCount);
            ds.Label = "隔水层高程";

            winCellCenterDSEdit win = new winCellCenterDSEdit(ds,project);

            win.Owner = this;
            win.ResizeMode = ResizeMode.NoResize;
            win.Unit += "(" + Domain.DomainLayer.UnitConverter.GetLength(_mdOption.Units.Length) + ")";
            win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            win.ShowInTaskbar = false;
            if (win.ShowDialog()==true)
            {
                this._gridData.WaterGrid.SetConfiningBeds(win.PcDs.Dataset.ToListData());
                if (project.CurrentDSData != null && project.CurrentDSData.Label == win.PcDs.Dataset.Label)
                    project.OnCurrentDSChanged();
                
            }


            

        }      


    }
}
